var maxSize = 12; 
var maxSizeH = 16; 
var glypSize = 14;
var numGlypL = 20; 
var numGlypLH = 15;
var maxLineHeight = 1;
var blockMargin = 0; 
var fontType = 3;
var viewGlypBody = false; 
var pSizeWidth = 280;
var pSizeHeight = 308;
var viewConsol = false;
var minLineHeight = maxLineHeight;
var minSize = maxSize; 
var numLines = 0;
var alltext ='';
var lists = new Array();
var item = new Array();

function on_loadedXML(oj)
{
	var xdoc  =  oj.responseXML
	item = xdoc.getElementsByTagName("item");
	putoutDetail(0);
}


function on_loadedXML_last(oj)
{
	var xdoc  =  oj.responseXML
	item = xdoc.getElementsByTagName("item");
	putoutDetail(1);
}

function on_loadedXML_last_imgBefore(oj)
{
	var xdoc  =  oj.responseXML
	item = xdoc.getElementsByTagName("item");
	putoutDetail(2);
}

function loadFile(url)
{
	sendRequest(on_loadedXML,'','GET',url,true,true);
}

function loadFile_last(url)
{
	sendRequest(on_loadedXML_last,'','GET',url,true,true);
}

function loadFile_last_imgBefore(url)
{
	sendRequest(on_loadedXML_last_imgBefore,'','GET',url,true,true);
}

function putoutDetail(n)
{
	var html = '';
	var title = '';
	var code = eval(n);
	var itemNum = 0;
	var itemOffset = 0
	if(code == 1||code == 2){
		itemNum = 1;
		itemOffset = 0;
	}
	else if(code == 0){
		itemNum = item.length;
		itemOffset = 1;
	}
	else{
		itemNum = item.length;
		itemOffset = 1;
	}
	var styleBodyDiv = '';
	var styleBodyDiv = 'style=" width:'+maxSize+'px; height:'+maxSize+'px;';
	var styleLbDiv = 'style="margin:'+22+'px 0 '+blockMargin+'px '+glypSize+'px;"';
	var styleBodyDivt = 'style=" width:'+eval(maxSize+4)+'px; height:'+eval(maxSize+4)+'px;';
	var styleLbDivt = 'style="margin:22px 4px '+blockMargin+'px '+glypSize+'px;"';	  
	//var styleLbDivt0 = 'style="margin:22px 48px '+blockMargin+'px '+glypSize+'px;"';
	var styleLbDivt0 = 'style="margin:22px 56px '+blockMargin+'px '+glypSize+'px;"';
	if(viewGlypBody){
		styleBodyDiv += 'border:1px solid #efefef;'
	}
	else{
	
	}

	if(viewConsol) trace("html.length");
	if(viewConsol)	trace(html.length);
	
	var stringArr = '';
	var style = '';
	var styleFont ='';
	var styleSize ='';
	var styleLh = '';
	var sd = '';
	var charNumL = 1;
	
	title = item[0].getElementsByTagName("description").item(0).firstChild.nodeValue;
	for( k = itemOffset ; k < itemNum; k++ )
	{
		title = item[k].getElementsByTagName("subject").item(0).firstChild.nodeValue;
		date = item[k].getElementsByTagName("published").item(0).firstChild.nodeValue;
		descValue = item[k].getElementsByTagName("description").item(0).firstChild.nodeValue;
		tagPoint = descValue.indexOf("<img",0);
		descriptionString = descValue.substring(0,tagPoint);
		imgSourceString = descValue.substring(tagPoint);
		imgAttirbutes =  getSourceAttribute(imgSourceString);
		imgAttirbutes =  getSourceAttribute(imgSourceString);
		if(descriptionString ==''){
		descriptionString = descValue;
	}
	html = descriptionString;
	photo = imgAttirbutes["src"]
	photo_width = imgAttirbutes["width"]
	alltext += item[k].getElementsByTagName("subject").item(0).firstChild.nodeValue + '\n';
	alltext += item[k].getElementsByTagName("description").item(0).firstChild.nodeValue+ '\n'+ '\n';
	
	charNumLt = 1;
	charNumL = 1;


	stringArr += '<div class="lbt" '+styleLbDivt0+'>';

	for( i = 0 ; i < title.length; i++ )
	{
		if(title.charAt(i) =='\n'){
			stringArr += '</div><div class="lbt" '+styleLbDivt+'>';
			charNumL = 1;
		}
		else{
			styleFont =' f'+fontType;
			styleSize =' s'+myRandom(minSize+4,maxSize+4);
			sd = styleBodyDivt;
			if((i)%numGlypLH ==0){
				styleLh = ' margin-top:'+myRandom(minLineHeight,maxLineHeight)+'px;"';
			}
			sd = styleBodyDivt + styleLh;
	
			style = ' class="ch'+styleFont+styleSize+'"'+sd;
			if(title.charAt(i) =='、'||title.charAt(i) =='。'){
				stringArr += '<div'+style+'><span style="position:relative; top:'+eval(-1*myRandom(minSize+4,maxSize+4)/2)+'; left:'+eval(myRandom(minSize+4,maxSize+4)*2/3)+';">'+pareseChaver(title.charAt(i))+'</span></div>';
			}
			else{
				stringArr += '<div'+style+'>'+pareseChaver(title.charAt(i))+'</div>';
			}
			if((charNumLt)%numGlypLH ==0){
				stringArr += '</div><div class="lbt" '+styleLbDivt+'>';
			}
			charNumLt ++;
		}
	}
	stringArr += '</div>'

	stringArr += '<div class="lb" '+styleLbDiv+'>';
	publishDate = date.split(',');
	dateY = publishDate[0];
	dateM = publishDate[1];
	dateD = publishDate[2];
	
	publishDateString = chDec(dateY,'s')+'年'+chDec(dateM,'d')+'月'+chDec(dateD,'d')+'日';
	publishDateString = setDateIndent(publishDateString,numGlypL);
	for( i = 0 ; i < publishDateString.length; i++ )
	{
		styleFont =' f'+fontType;
		styleSize =' s'+myRandom(minSize,maxSize);
		sd = styleBodyDiv;
		if((i)%numGlypL ==0){
		}
		sd = styleBodyDiv + styleLh;
		
		style = ' class="ch'+styleFont+styleSize+'"'+sd;
		stringArr += '<div'+style+'>'+pareseChaver(publishDateString.charAt(i))+'</div>';
	}
	stringArr += '</div>';
	
	if(photo!=null){
		leftPosition = (pSizeWidth-photo_width)*0.5;
		if(code==2){
			stringArr += '<div class="imageBox" style="overflow:hidden; width:'+pSizeWidth+'px; height:'+pSizeHeight+'px;"><img src="'+photo+'" height="'+pSizeHeight+'" alt="" style="position:relative; left:'+leftPosition+';"></div><div style="width:20px; height:45px; float:right;)"></div>'
		}
	}
	
	stringArr += '<div class="lb" '+styleLbDiv+'>';
	for( i = 0 ; i < html.length; i++ )
	{
	
	
	
		if(html.charAt(i) =='\n'){
		stringArr += '</div><div class="lb" '+styleLbDiv+'>';
		charNumL = 1;
		}
		else{
			styleFont =' f'+fontType;
			styleSize =' s'+myRandom(minSize,maxSize);
			sd = styleBodyDiv;
			if((i)%numGlypL ==0){
			
			}
			sd = styleBodyDiv + styleLh;
			
			style = ' class="ch'+styleFont+styleSize+'"'+sd;
			if((charNumL)%numGlypL ==0 && html.charAt(i+1)!=null){				//add 061006
				if(prohibiCh(html.charAt(i+1))){								//add 061006
					stringArr += '</div><div class="lb" '+styleLbDiv+'>';		//add 061006
					charNumL ++;												//add 061006
				}																//add 061006
			}
			if(html.charAt(i) =='、'||html.charAt(i) =='。'){
				stringArr += '<div'+style+'><span style="position:relative; top:'+eval(-1*myRandom(minSize,maxSize)/2)+'; left:'+eval(myRandom(minSize,maxSize)*2/3)+';">'+pareseChaver(html.charAt(i))+'</span></div>';
			}
			else{
				stringArr += '<div'+style+'>'+pareseChaver(html.charAt(i))+'</div>';
			}
			if((charNumL)%numGlypL ==0){
				stringArr += '</div><div class="lb" '+styleLbDiv+'>';
			}
			charNumL ++;
		}
	}
	if(photo!=null){
		if(code ==2){
			stringArr += '</div>';
		}
		else{
				stringArr += '</div><div class="imageBox" style="overflow:hidden; width:'+pSizeWidth+'px; height:'+pSizeHeight+'px;"><img src="'+photo+'" height="'+pSizeHeight+'" alt="" style="position:relative; left:'+leftPosition+';"></div>'
		}
	}
	else{
		stringArr += '</div>';
	}
	if(code == 0) stringArr += '<div class="borderBox"></div>';
}
stringArr += '<div class="clear"></div>'

if(viewConsol) trace("html.length");
if(viewConsol) trace(html.length);
if(viewConsol) trace(stringArr);

document.getElementById("glyps").innerHTML= stringArr;



if(!viewConsol) document.getElementById("consol").style.display = 'none';
}


function trace(x){
document.getElementById("consol").innerHTML +='<br>'+x;
}

function dumpImg(x){
document.getElementById("dump").innerHTML +=x;
}
function dumpClear(){
document.getElementById("dump").innerHTML ="";
}

function printState(x){
document.getElementById("status").innerHTML =x;
}

function myRandom(x,y){
var num=0;
num = Math.floor(Math.random()*(y-x) + x);
return num;
}


function chDec(d,code){
res = '';
if(code=='s'){
res += pareseChaverDec(d);
}
else if(code=='d'){
decd = eval(d);
oku = Math.floor(decd/100000000);
man = Math.floor((decd%100000000)/10000);
sen = Math.floor((decd%10000)/1000);
hyaku = Math.floor((decd%1000)/100);
jyu = Math.floor((decd%100)/10);
ich = decd%10;

if(oku !=0){
res += pareseChaverDec(oku.toString())+"億";
}
if(man !=0){
res += pareseChaverDec(man.toString())+"万";
}
if(sen !=0){
if(sen ==1) res += "千";
else res += pareseChaverDec(sen.toString())+"千";
}
if(hyaku !=0){
if(hyaku ==1) res += "百";
else res += pareseChaverDec(hyaku.toString())+"百";
}
if(jyu !=0){
if(jyu ==1) res += "十";
else res += pareseChaverDec(jyu.toString())+"十";
}
if(ich !=0){
res += pareseChaverDec(ich.toString());
}

}
return res;
}

function setDateIndent(dateString,chNum){
indentChNum = chNum - dateString.length;
indentString = '';
for(i =0; i<indentChNum; i++){
indentString += ' ';
}
return indentString+dateString;

}

function getSourceAttribute(str){
var searchStr = '\"';
var replaceStr = '';
var re = new RegExp(searchStr,"g");
var result = str.replace(re,replaceStr);

result = result.substring(1,str.length-2);
temp = result.split(" ");
atr = new Array();
var attributeArr = new Array();
for(i=0; i<temp.length; i++){
atr[i] = temp[i].split("=");
attributeArr[atr[i][0]] = atr[i][1];
}
return attributeArr;
}